package configs

import (
	"context"

	"github.com/gogf/gf/v2/frame/g"
)

type Token struct {
	Secret string `json:"secret"`
}

var _tempToken *Token = nil

func GetToken(ctx context.Context) *Token {
	tokenVar, err := g.Cfg().Get(ctx, "token")
	if err != nil {
		g.Log().Line(true).Error(ctx, "token is not set")
		return _tempToken
	}

	token := &Token{}
	err = tokenVar.Scan(token)
	if err != nil {
		g.Log().Line(true).Error(ctx, "token is not valid")
		return _tempToken
	}

	if token.Secret == "" {
		g.Log().Line(true).Error(ctx, "token secret is not set")
		return _tempToken
	}

	_tempToken = token

	return token
}
